package com.hl.shifangzhiyu.web;

import com.hl.shifangzhiyu.pojo.Respond;
import com.hl.shifangzhiyu.service.RespondService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController //RESTful 控制器 http请求响应
@RequestMapping("/respond") //映射基础路径
public class RespondController {
    @Autowired
    private RespondService respondService;
    @PostMapping//处理POST请求
    public String add(@RequestBody Respond respond){
        //@RequestBody 表示接收json数据 转换成java对象
        respondService.add(respond);
        return "回答已添加";
    }
    @GetMapping//处理GET请求
    public List<Respond> getAll(){
        return respondService.listAll();
    }
}
